<template>
  <div>
    <MyGoods :data="goodList"
    @change-num="fn"
    @del-event="delEvent"
    ></MyGoods>
  </div>
</template>

<script>
import MyGoods from '@/components/my-goods.vue'
export default {
  data(){
    return {
       goodList: [
        {
          name: "诸葛亮",
          price: 1000,
          num: 1,
          checked: false,
        },
        {
          name: "蔡文姬",
          price: 1500,
          num: 1,
          checked: false,
        },
        {
          name: "妲己",
          price: 2000,
          num: 1,
          checked: false,
        },
        {
          name: "鲁班",
          price: 2200,
          num: 1,
          checked: false,
        },
      ],
    }
  },
  components:{
    MyGoods,
  },
  methods:{
    fn(value){
      // console.log(1)
      // 遍历这个数组，把value值给到每个item的num
    this.goodList =   this.goodList.map(item=>{
        item.num = value
        return item
      })
    },
    // 删除功能
    delEvent(index){
    //  通过索引找到id
    this.goodList.splice(index,1)
    }
  }
}
</script>

<style scoped>

</style>